package com.yxp.webtest.bean;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.PriorityOrdered;

/**
 * @author      : yang.xp
 * @date        : 2021/10/13 17:07
 * @description : BeanPostProcessor 的测试， 可以通过 PriorityOrdered 来排序
 */
@Slf4j
public class BeanPostProcessPojo implements BeanPostProcessor, BeanFactoryPostProcessor, PriorityOrdered {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        log.info(this.getClass().getSimpleName() + " invoke postProcessBeforeInitialization " + beanName + " "  + bean.getClass().getName());
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        log.info(this.getClass().getSimpleName() + " invoke postProcessAfterInitialization " + beanName + " "  + bean.getClass().getName());
        return bean;
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        log.info(this.getClass().getSimpleName() + " invoke postProcessBeanFactory");
    }

    @Override
    public int getOrder() {
        return 2;
    }
}
